#include "SCI_HAL_QE.h"

/* Rarely called initialization functions for the SCI module receive 
   the corresponding channel as a parameter */

void vfnSCI_SetBaudRate (uint8 u8channel, uint16 u16baudrate)
{
    if (u8channel == 1)
    {
        SCI1BD = u16baudrate;
    }
    else
    {
        SCI2BD = u16baudrate;
    }
}

void vfnSCI_Init (uint8 u8channel)
{
    if (u8channel == 1)
    {
        SCI1C1 = SCI1_CONTROL_REG1;
        SCI1C2 = SCI1_CONTROL_REG2;
        SCI1C3 = 0x00;   
    }
    else
    { 
        SCI2C1 = SCI2_CONTROL_REG1;
        SCI2C2 = SCI2_CONTROL_REG2;
        SCI2C3 = 0x00;  
    }
}

/* Commonly called functions for SCI channel 1 */

void vfnSCI1_SendByte (uint8 u8data)
{
    SCI1D = u8data;
}

uint8 u8SCI1_TxBufferEmpty (void)
{
    return SCI1S1_TDRE;
}

uint8 u8SCI1_TxComplete (void)
{
    return SCI1S1_TC;
}

uint8 u8SCI1_CheckOverrun (void)
{
    return SCI1S1_OR;
}

uint8 u8SCI1_ReadByte (void)
{
    return SCI1D;
}

uint8 u8SCI1_RxPending (void)
{
    return SCI1S1_RDRF;
}

/* Commonly called functions for SCI channel 2 */

void vfnSCI2_SendByte (uint8 u8data)
{
    SCI2D = u8data;
}

uint8 u8SCI2_TxBufferEmpty (void)
{
    return SCI2S1_TDRE;
}

uint8 u8SCI2_TxComplete (void)
{
    return SCI2S1_TC;
}

uint8 u8SCI2_CheckOverrun (void)
{
    return SCI2S1_OR;
}

uint8 u8SCI2_ReadByte (void)
{
    return SCI2D;
}

uint8 u8SCI2_RxPending (void)
{          
    return SCI2S1_RDRF;
}


